package cn.wsn2018.tools.config;

import cn.wsn2018.tools.interceptor.SessionInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by NZX on 2018/12/18.
 */
@Configuration
/**
 * 注册拦截器
 */
public class WebAppConfig extends WebMvcConfigurerAdapter{
    @Override
    public void addViewControllers( ViewControllerRegistry registry ) {
        registry.addViewController( "/" ).setViewName( "forward:/login.html" );
        registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
        super.addViewControllers( registry );
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SessionInterceptor()).addPathPatterns("/protocol/**")
                .excludePathPatterns("/protocol/login",
                        "/protocol/IDCode",
                        "/protocol/checkIDCode",
                        "/protocol/getpublickey");
//        "/protocol/admin",
    }

}
